import os
import cuscmd
import time
import re
from Swipe import Swipe
from decimal import Decimal, getcontext
currentPath = os.getcwd()
print('当前路径：{}'.format(currentPath))
out=cuscmd.executeCommand('adb/adb devices',currentPath)
deviceListStr=out.decode(encoding="utf-8")
print('设备：{}'.format(deviceListStr))
deviceList=re.findall(r'[A-Za-z0-9]+',deviceListStr)
total = len(deviceList)
if len(deviceList) > 4:
    dtotal = Decimal(total)
    deviceNum = (dtotal-Decimal(4))/Decimal(2)
    print('发现'+str(deviceNum)+'台手机设备')
    # 设备id列表
    deviceId = []
    for i in range(0,int(deviceNum)):
        deviceId.append(deviceList[4+2*i])
    print(deviceId)
    # 创建线程
    taskJobs = []
    for i in deviceId:
        taskJob=Swipe(i,'快手任务',currentPath)
        taskJob.start()
        taskJobs.append(taskJob)
    # 等待线程全部结束
    for t in taskJobs:
        t.join()
else :
    print('未发现任何手机设备')
print('停止运行')